<template>
  <view class="container">
    <u-navbar
      :is-fixed="true"
      :border-bottom="false"
      :is-back="true"
      :background="{ background: '#5697F1' }"
      title="乘车人列表"
      title-color="#fff"
    >
    </u-navbar>
    <view class="people">
      <view class="each" v-for="(p, pIndex) in peoples" :key="pIndex">
        <view class="head">
          <view class="name">{{p.realname}}</view>
          <image class="img" src="/static/images/edit.svg" @click="doModify(p)"></image>
        </view>
        <view class="cardno">{{p.cardno}}</view>
      </view>

      <button class="submit" @click="doAdd">添加</button>
    </view>
  </view>
</template>

<script>
import { getPass, updatePass } from '../../api/system/api'
export default {
  data() {
    return {
      peoples: [],
      userInfo: {}
    };
  },
  mounted() {
    this.refreshData()
  },
  onShow() {
    uni.$off('refreshData')
    uni.$once('refreshData', (data) => {
      this.refreshData()
    })
  },
  methods: {
    doAdd() {
      this.$u.route('/pages/interest/add')
    },
    changeCheck(row, check) {
      console.log(row, check)
      updatePass(row.id, {
        choose: check.value ? 'true' : 'false'
      })
    },
    refreshData() {
      uni.getStorage({     
        key:'userInfo',
        success: (res) => {
          this.userInfo = res.data;
          getPass({
            page: 1,
            pageSize: 10,
            userId: this.userInfo.id
          }).then(res => {
            console.log(res)
            if (res.code === 200) {
              this.peoples = res.data.data
              this.peoples.forEach((v, i) => {
                this.peoples[i].choose = v.choose === 'true' ? true : false
              })
            }
          })
        }
      })
    },
    doModify(data) {
      console.log(data)
			this.$u.route('/pages/interest/add', {
        data: JSON.stringify(data)
			})
    }
  },
};
</script>

<style lang="scss" scoped>
.container {
  background-color: #fff;
  min-height: 100vh;
  overflow: hidden;
  padding: 2rpx;
}
.add {
  text-align: center;
  font-size: 30rpx;
  line-height: 120rpx;
}
.people {
  padding: 30rpx;
  background: #fff;
  width: calc(100% - 60rpx);
  margin: auto;
  border-radius: 20rpx;
  .img {
    width: 30rpx;
    height: 30rpx;
  }

  .each {
    padding: 20rpx 0 20rpx 30rpx;
    border-bottom: 1rpx solid #e4dada;
    position: relative;
    .head {
      display: flex;
      width: 100%;
      justify-content: space-between;
      font-weight: bold;
    }
    .cardno {
      margin-top: 10rpx;
    }
  }

  .add {
    text-align: center;
    margin-top: 30rpx;
    width: 100%;
    font-weight: bold;
  }

  .check {
    position: absolute;
    left: -30rpx;
    top: 30rpx;
  }
}

.submit {
  margin: 60rpx 0 0;
  border: none;
  width: 100%;
  height: 86rpx;
  line-height: 86rpx;
  box-sizing: border-box;
  border-radius: 15rpx;
  background-color: #5f88ff;
  color: #ffffff;

  &::after {
    content: none;
  }

  &::before {
    content: none;
  }

  &[disabled='true'] {
    background: #e4e4e4;
    font-size: 36rpx;
    font-family: Source Han Sans CN;
    font-weight: 500;
    color: #ffffff;
  }
}
.add {
  width: 40%;
  height: 60rpx;
  line-height: 60rpx;
  margin: 60rpx auto 0;
  background-color: #ff5757;
}
</style>
